// 用户相关接口
import http from '../utils/request.js';

/**
 * 获取用户手机号  （无用）
 */
export function getPhoneNumber({ openId, iv, encryptedData }) {
  return http.post('wx_login/getPhoneNumber', {
    openId,
    iv,
    encryptedData,
  });
}

/**
 * 发送验证码
 */

export const getVerifyCode = ({ phonenumber }) => {
  const source = '1'; //1:注册  2：修改密码
  return http.$post('dengLuHm/faSongCode', {
    phonenumber,
    source,
  });
};


/**
 *  无短信验证码  注册
 *  TODO: 测试;
 */

export const handleWXRegister = ({ phone, invite_key, password }) => {
  return http.$post('dengLuHm/gogogo_without_vCode', {
    phone,
    invite_key,
    password,
  });
};

/**
 *  有短信验证码  注册
 *  TODO: 测试;
 * DONE:  完善 测试  dengLuHm/zhuCeNe
 */

export const handleRegister = ({
  token,
  id,
  phonenumber,
  passwd,
  invite_key,
  code,
  wx_openid_xin,
  userSource,
}) => {
  phonenumber = String(phonenumber);
  const xin_openId = wx_openid_xin;
  return http.$post('dengLuHm/zhuCeNe', {
    phonenumber,
    passwd,
    token,
    id,
    wx_openid_xin,
    code,
    invite_key,
    xin_openId,
    user_source: userSource || '1' //1：小程序  2：电脑  3：APP'
  });
};
/**
 * DONE
 * TODO: 测试;
 *  用户 账号密码登录
 *
 */

export const handleLogin = ({ phonenumber, passwd, wx_openid_xin }) => {
  const xin_openId = wx_openid_xin;
  return http.$post('dengLuHm/gogogo', {
    wx_openid_xin,
    phonenumber,
    passwd,
    xin_openId,
  });
};

/**
 * DOING
 * FEATURE: 获取当前用户的活动场次列表
 *
 */

export const getUserSceneList = ({ type, showCount, currentPage }) => {
  return http.$post('newHuoDongHm/latelyHuoDongList', {
    type,
    showCount,
    currentPage,
  });
};

export const getSwiper = ({ sys_type, bg_type }) => {
  return http.$post('dengLuHm/getLbt', {
    sys_type,
    bg_type,
  });
};

export const getCanrouselList = () => {
  return http.$post('dengLuHm/getLbt', {
    sys_type: '2',
    bg_type: 'app_shop',
  });
};
// 获取商品列表
export function getProdList(pObj) {
  return http.$$request('product/list2', 'GET', {
    currentPage: pObj.currentPage,
    showCount: pObj.showCount
  });
}
// 获取商品详情
export function getProdDetail(id, tenantId) {
  const tmpParamObj = {
    productId: id,
    tenantId,
  };
  if (!tenantId) {
    delete tmpParamObj.tenantId;
  }
  return http.$$request('product/getProductInfo2', 'GET', {
    ...tmpParamObj
  });
}

// 获取海报二维码
export const getPosterQRcode = ({ page, scene, logoPath }) => {
  return http.$post('newHuoDongHm/getSmallCodeInviter1', {
    page,
    scene,
    logoPath,
  });
};

// 获取现金奖励数据列表
export const getCashList = ({ showCount, currentPage }) => {
  return http.$post('info/startActivityList', {
    showCount,
    currentPage,
  });
};
/**
 *  dengLuHm/gogogo
 *  根据token获取用户信息
 */
export const getUserInfo = ({ token }) => {
  return http.$post('dengLuHm/gogogo', {
    token,
  });
};

/**
 *
 *  获取邀请情况信息
 */
export const getInviteList = ({ showCount, currentPage }) => {
  return http.$post('yaoQing/myYaoQingList', {
    showCount,
    currentPage,
  });
};
/*
  获取红包奖励列表

 */
export const getHbList = ({ query_type }) => {
  return http.$post('hb/getPhoneRedBaoList', {
    query_type,
    currentPage: '1',
    showCount: '100',
  });
};
export const getInviterHbList = ({ query_type }) => {
  return http.$post('hb/getMyRedBaolistPage', {
    query_type: 'inviter',
    currentPage: '1',
    showCount: '100',
  });
};
/*
    设置乘风破浪是否参与
 */
export const setIsJoin = () => {
  return http.$post('host/canJia90Profit');
};
/**
  *
  *
  * @param {*} param0
  */
export const getTokenById = ({ scene }) => {
  return http.$post('newHuoDongHm/getTokenById', {
    scene,
  });
};

// 购买课程
export const purchaseCourse = ({ albumId }) => {
  return http.$post('kpPay/kpWxPay', {
    album_id: albumId,
    pay_type: 'wx',
    type: '1',
  });
};

// 购买礼物包场
export const purchaseGiftAllFree = ({ splid }) => {
  return http.$post('kpPay/functionWxPay', {
    splid,
    pay_type: 'wx',
    type: '5',
  });
};

// 生成猜红包二维码
export const generateGuessHbQrcode = ({ liveId }) => {
  return http.$post('question/getQrUrl', {
    url: `https://www.hudongmiao.com/hb/method1?splid=${liveId}`,
    type: 'question'
  });
};
// 获取猜红包充值状态
export const getGuessHbStatus = ({ splid, token }) => {
  return http.$post('hb/getPhotoUserInfo', {
    splid,
    token,
  }, 'cancelLoading');
};

// 设置猜红包模式
export const setGuessHbMod = ({ splid, token, type, guess_money }) => {
  return http.$post('hb/setGuessMoney', {
    splid,
    token,
    type,
    guess_money,
  }, 'cancelLoading');
};

export const getMyInviteList = ({ showCount, currentPage }) => {
  return http.$post('yaoQing/myYaoQingList', {
    income_sort: "",
    lastLoginTime: "2",
    showCount,
    currentPage,
    userInfo: "",
    zhuceTime: "0",
  });
};

// 我的页->修改信息页获取用户资料
export function getUserProfileInfo() {
  return http.$post('host/getUserInfo', {});
}

//  修改用户信息
export function modifyUserInfo(paramObj) {
  return http.$post('host/personalInformation', paramObj);
}

/** 获取「嗨喵豪礼相送」弹窗相关信息 */
export const getJoymewGiftsInfo = () => {
  return http.$get('gradeUp/getJoymewGifts');
};

/** 获取绑定微信号二维码 */
export const getBindWechatQrCode = () => {
  return http.$get('host/bangDingVxQrCode');
};

/** 保存「嗨喵豪礼相送」弹窗奖励为已领取状态 */
export const setJoymewGiftsChecked = () => {
  return http.$post('hb/saveHb');
};
